<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="banner-manger-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
			<template #top>
					<view class="u-p-20"  style="background-color: #fff;">
						<u-search :searchIconFlag="true" v-model="searchText" input-align="center" placeholder="输入名称筛选" 
						height="70" :border-color="'#FFBB1A'" :bg-color="'#fff'" 	:show-action="false" @change="reloadFn" @search="reloadFn"></u-search>
					</view>
			</template>
			
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="banner-container u-m-b-20" v-for="(item,index) in dataList" :key="index" >
				<view class="banner-section u-p-l-35  u-p-r-35">
					<view class="u-p-t-28 u-p-b-28" style="border-bottom:1px solid #EAEAEA;">
						<u-radio-group v-model="chooseItem" active-color="#ffbb1a">
							<u-radio shape="circle" :name="item.id">
								<view style="width: 100%;" class="u-flex u-m-l-20">
									<image :src="item.url" mode="" class="u-m-r-20" style="width: 130rpx;height: 130rpx;"></image>
									<view style="flex:1;">
										<view class="u-flex u-col-top">
											<view class="item-name u-line-1" style="flex:1;">{{item.name}}</view>
										</view>
									</view>
								</view>
							</u-radio>
						</u-radio-group>
					</view>
						
				</view>
			</view>
			<template #bottom>
				<view  class="u-p-20">
					<view @click="sendData" style="width: 100%;background: linear-gradient(-90deg, #FFBB1A, #FFBB1A);border-radius: 45rpx;" class="u-text-center u-p-t-20 u-p-b-20" >确定</view>
				</view>	
			</template>
			
		</z-paging>
		
	</view>
</template>

<script>
	import { useShopStore } from '@/store/shop.js';
	import { mapState } from 'pinia';
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				searchText:'',
				chooseItem:'',
			}
		},
		computed:{
			...mapState(useShopStore, {storeShop: 'shop'})
		},
		props:{
			initId:{
				type:String,
				default:''
			},
		},
		mounted(){
			this.chooseItem = this.initId
		},
		methods: {
			reloadFn(){
				this.$refs.paging.reload();
			},
			goSign(){
				this.$mRouter.push({
					route: '/pages/sale/homePageConfig/bannerDetails' 
				})
			},
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					shopId:this.storeShop.id,
					IsPublished:true
					// IsSeller:true
				}
				if (this.searchText !== '') {
					params.Name = this.searchText;
				}
				uni.showLoading({
					title: '加载中...',
					mask: false
				});
				const res = await this.$newHttp.get('api/SalesPromotion/GetSalesPromotionBySeller', { params: params } );
				uni.hideLoading({
					title: '加载中...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
				}else{
					this.$refs.paging.complete(false);
				}
			},
			sendData(item) {
				let sendName = '';
				if(this.chooseItem !== ''){
					sendName =  this.dataList.find(item=>{return item.id === this.chooseItem}).name;
				}
				let obj = {
					id:this.chooseItem,
					name:sendName
				}
				console.log(obj);
				this.$emit('choose',obj);
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.banner-manger-content {
		height: 100%;
		.banner-container{
			.banner-section{
				background-color: #fff;
				.banner-text{
					font-size: 28rpx;color: #999;
				}
				.item-name{
					font-weight: 500;
					font-size: 24rpx;
				}
				.item-val{
					display: inline-block;
					font-size: 20rpx;
					box-sizing: border-box;
					border-radius: 4px;
					
					.item-val-text{
						display: inline-block;
						box-sizing: border-box;
						padding: 0rpx 10rpx;
					}
					.item-val-specifica-title{
						border-right: 1px solid #ff551a;
						background-color: #FFE1D6;
						color: #FF551A;
						border-top-left-radius: 4px;
						border-bottom-left-radius: 4px;
					}
					.item-val-specifica-text{
						color: #FF551A;
					}
					.item-val-owner-title{
						border-right: 1px solid #C09A87;
						background-color: #FAF1DF;
						color: #B88D77;
						border-top-left-radius: 4px;
						border-bottom-left-radius: 4px;
					}
					.item-val-owner-text{
						color: #B88D77;
					}
				}
			}
		}
	}


</style>
